package com.jzo2o.customer.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jzo2o.customer.mapper.BankAccountMapper;
import com.jzo2o.customer.model.domain.BankAccount;
import com.jzo2o.customer.model.dto.request.BankAccountUpsertReqDTO;
import com.jzo2o.customer.service.BankAccountService;
import com.jzo2o.mvc.utils.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BankAccountServiceImpl extends ServiceImpl<BankAccountMapper, BankAccount> implements BankAccountService {
    @Autowired
    private BankAccountMapper bankAccountMapper;

    /**
     * 新增或更新银行账号信息接口
     *
     * @param dto
     */
    @Override
    public void addupt(BankAccountUpsertReqDTO dto) {
        BankAccount bean = BeanUtil.toBean(dto, BankAccount.class);
        BankAccount bankAccount = bankAccountMapper.selectById(dto.getId());
        if (ObjectUtil.isEmpty(bankAccount)) {
            bean.setId(UserContext.currentUserId());
            bankAccountMapper.insert(bean);
        }
        bankAccountMapper.updateById(bean);
    }
}
